<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>角色修改</title>
<link rel="stylesheet" href="../../../files/css/layui.css" media="all">
<link rel="stylesheet"
	href="https://cdn.bootcss.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://cdn.bootcss.com/jquery/2.1.1/jquery.min.js"></script>
<script
	src="https://cdn.bootcss.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<style type="text/css">
#goodsImg {
	position: relative;
	left: 110px;
}
</style>
</head>
<body>

	<fieldset class="layui-elem-field layui-field-title"
		style="margin-top: 20px;">
		<legend>角色修改列表</legend>
	</fieldset>

	<form class="layui-form" action="../../../role/saveOrUpdate.action"
		method="post">
		<input type="hidden" id="roleId" name="roleId">
		<div class="layui-form-item">
			<label class="layui-form-label" style="width: 100px;">角色名称</label>
			<div class="layui-input-inline">
				<input type="text" name="roleName" id="roleName"
					lay-verify="required" placeholder="请输入" autocomplete="off"
					class="layui-input">
			</div>
		</div>
		<div class="layui-form-item">
			<label class="layui-form-label" style="width: 100px;">角色编码</label>
			<div class="layui-input-inline">
				<input type="text" name="roleCode" required="required" value="UTF-8"
					lay-verify="required" placeholder="请输入" autocomplete="off"
					class="layui-input">
			</div>
		</div>

		<div class="layui-form-item">
			<label class="layui-form-label" style="width: 100px;">备注</label>
			<div class="layui-input-inline">
				<textarea placeholder="请输入内容" name="roleDesc" class="layui-textarea"></textarea>
			</div>
		</div>

		<div class="layui-form-item">
			<label class="layui-form-label" style="width: 100px;">是否有效</label>
			<div class="layui-input-inline">
				<select name="isva" id="isva" required="required">
					<option value="0">无效</option>
					<option value="1">有效</option>
				</select>
			</div>
		</div>

		<div class="layui-form-item">
			<label class="layui-form-label" style="width: 100px;">赋予模块</label>
			<div class="layui-input-inline" id="tbModule"></div>
		</div>
		<input type="hidden" id="str" name="str" />

		<div class="layui-form-item">
			<div class="layui-input-block">
				<input onclick="aa()" type="submit" class="layui-btn" lay-submit=""
					lay-filter="goodsUpdate" value="立即提交">
				<button type="reset" class="layui-btn layui-btn-primary">重置</button>
			</div>
		</div>
	</form>


	<script src="../../../files/js/layui.js"></script>
	<script type="text/javascript" src="../../../commom/js/base.js"></script>
	<script type="text/javascript" src="../../../files/js/jquery.min.js"></script>
	<script>


//赋值到INPUT
function aa(){
	var bb="";
	var temp="";
	var a=document.getElementsByName("ro");
	//alert(a.length);
	for(var i=0;i<a.length; i++){
		if(a[i].checked){
			temp=a[i].value;
			if(bb==""){
				bb=temp;
			}else{
				bb=bb+","+temp;
			}
		}
	}
	alert(bb);
	$("#str").val(bb);
}


layui.use(['form','tree', 'layer'], function(){
  var form = layui.form
  ,layer = layui.layer
  ,$ = layui.$;
  form.on('submit(goodsUpdate)',function(){
	  
			parent.location.reload(); // 父页面刷新
	 
	  
  });
   
//获得角色
  var url = getRootPath()+"module/findAll.action";
   
	$.post(url,null,function(msg){
		
		var data = msg[1];
		for(var i=0;i<data.length;i++){
			//alert(data[i].roleId);
			$("#tbModule").append("<input type='checkbox' value="+data[i].modId+" name='ro' title="+data[i].modName+">");
		}
		var urls = getRootPath()+"module/findRoleModule.action";
		
		var datas  = {"roleId":msg[0].roleId};  
		 
		$.post(urls,datas,function(data){
			alert("   aa  "+data.length+" sss "+msg[0].roleId);
			
			var a=document.getElementsByName("ro"); 
			for(var i=0;i<data.length;i++){  
				//alert(data[i].roleId);
				//$("#one").append("<input type='text'  value="+data[i].roleId+" name='rr' title="+data[i].roleId+">");
				for(var j=0;j<a.length; j++){
					if(data[i].modId==a[j].value){
						a[j].checked=true;
					}
				}
			}
			//form表单重新渲染
			form.render();
		},dataType="JSON");
		//form表单重新渲染
		 
		form.render();
	},"JSON");
  
  /* var url="GoodsServlet";
  var data= {action:'tree'};
  $.post(url,data,function(data){
	  eval("var data="+data);
	  layui.tree({
		  elem: '#goodsTypeTree' //传入元素选择器
		  ,nodes: data
		  ,click: function(node){
			 $("#goodType").val(node.name);
			 
			 $("#goodTypeId").val(node.id);
		  }  
		});
  }); */
   layer.msg('数据加载中', {
	  icon: 1,
	  time: 10 //2秒关闭（如果不配置，默认是3秒）
	}, function(){
		//进行渲染
		form.render();
	});  
  
  
  
});
</script>

</body>
</html>